{extend name="../../../view/public/base" /}

{block name="css"}
<style>
    body {
        background-color: #F2F2F2;
    }
</style>
{/block}

{block name="body"}
<div style="padding: 20px; background-color: #F2F2F2;">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-tab layui-tab-brief" lay-filter="log">
                <ul class="layui-tab-title">
                    <li class="layui-this" data-log-name="sms_send_log">短信发送记录</li>
                </ul>
            </div>
            <!--搜索区域-->
            <div class="layui-card">
                <div class="layui-collapse" lay-accordion="" lay-filter="search">
                    <div class="layui-colla-item">
                        <h2 class="layui-colla-title">查询条件</h2>
                        <div class="layui-colla-content">
                            <form id="searchForm" class="layui-form" lay-filter="searchForm" autocomplete="off">

                                <div class="layui-form-item layui-inline">
                                    <label class="layui-form-label">序号</label>
                                    <div class="layui-input-inline">
                                        <input type="number" name="id" placeholder="请输入序号"
                                               class="layui-input">
                                    </div>
                                </div>

                                <!--事件event 在页面渲染时传过来-->
                                <div class="layui-form-item layui-inline">
                                    <label class="layui-form-label">事件</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="event" placeholder="请输入事件"
                                               class="layui-input">
                                    </div>
                                </div>
                                <!--手机号mobile 在页面渲染时传过来-->
                                <div class="layui-form-item layui-inline">
                                    <label class="layui-form-label">手机号</label>
                                    <div class="layui-input-inline">
                                        <input type="number" name="mobile" placeholder="请输入手机号"
                                               class="layui-input">
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <div class="layui-input-block">
                                        <button class="layui-btn layui-btn-normal" type="button" lay-submit lay-filter="searchBtn">
                                            搜索
                                        </button>
                                        <button class="layui-btn layui-btn-primary" type="button" onclick="resetForm()">
                                            重置
                                        </button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>

            <!--列表区域-->
            <div class="layui-card" style="background-color: #F2F2F2">
                <table id="list" lay-filter="listFilter"></table>

                <!--工具栏-->
                <script type="text/html" id="listToolbar">
                    <a class="layui-btn layui-btn-sm layui-bg-black" lay-event="refresh" title="刷新"><i class="layui-icon layui-icon-refresh" style="font-size: 8px !important;"></i> </a>
                    <!--<a class="layui-btn layui-btn-sm layui-btn-normal" lay-event="add" title="新增">新增</a>
                    <a class="layui-btn layui-btn-sm layui-btn-danger" lay-event="del" title="删除">删除</a>-->
                </script>

                <!--租户ID-->
                <script type="text/html" id="member_id">
                    {{ d.member_id }}
                </script>
                <!--手机号-->
                <script type="text/html" id="mobile">
                    {{ d.mobile }}
                </script>
                <!--验证码-->
                <script type="text/html" id="code">
                    {{ d.code }}
                </script>
                <!--次数-->
                <script type="text/html" id="times">
                    {{ d.times }}
                </script>
                <!--ip-->
                <script type="text/html" id="IP">
                    {{ d.ip }}
                </script>
                <!--创建时间-->
                <script type="text/html" id="create_time">
                    {{ formatDate(d.create_time) }}
                </script>


                <!--状态开关-->
                <script type="text/html" id="listBar">
                    <!--<a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="edit">编辑</a>-->
                    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</a>
                </script>
            </div>
        </div>
    </div>
</div>

{/block}

{block name="js"}
<script>
    var element, layer, form, table, bwajax, $;

    layui.use(['element', 'layer', 'form', 'table', 'bwajax'], function () {
        element = layui.element;
        layer = layui.layer;
        form = layui.form;
        table = layui.table;
        bwajax = layui.bwajax.instance();
        $ = layui.jquery;

        //用模板渲染的数据渲染form
        bwRenderForm({:json_encode($where)});
        //执行列表
        table.render({
            elem: '#list',
            url: "{:Url('/manage/cloud.log.smsLog/index')}",
            where: getWhere(),
            response: {
                statusCode: 200,  //规定成功的状态码，默认：0
            },
            parseData: function (res) { //res 即为原始返回的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": res.data.data.total, //解析数据长度
                    "data": res.data.data.list //解析数据列表
                };
            },
            toolbar: '#listToolbar',
            cols: [[
                {type:'checkbox', fixed: 'left'},
                {field: 'id', title: '序号', align: 'center', fixed: 'left'},
                {field: 'member_id', title: '租户ID', align: 'center', templet: '#member_id'},
                {field: 'event', title: '事件', align: 'center', templet: '#event'},
                {field: 'mobile', title: '手机号', align: 'center', templet: '#mobile'},
                {field: 'code', title: '验证码', align: 'center', templet: '#code'},
                {field: 'times', title: '验证次数', align: 'center', templet: '#times'},
                // {field: 'days', title: '有效天数', align: 'center', templet: '#days'},
                {field: 'ip', title: 'IP', align: 'center', templet: '#ip'},
                {field: 'create_time', title: '创建时间', align: 'center', templet: '#create_time'},

                {title: '操作', toolbar: '#listBar', align: 'center', fixed: "right"}
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 10,
            page: true
        });

        //监听表格头部工具栏事件
        table.on('toolbar(listFilter)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            switch (obj.event) {
                case 'refresh':
                    reload();
                    break;
                case 'add':
                    bwOpenIframe("{:Url('/manage/cloud.log.smsLog/add')}", '新增');
                    break;
                case 'del':
                    var checkStatus = table.checkStatus('list');
                    var data = checkStatus.data;

                    var idsArr = [];
                    data.forEach(function(value) {
                        idsArr.push(value.id);
                    });
                    ids = idsArr.join(',');

                    if(!ids) layer.msg('没有选中行', {icon: 2});
                    else del(ids);

                    break;
            }
        });

        //监听工具条
        table.on('tool(listFilter)', function (obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）

            switch (layEvent) {
                case 'edit':
                    bwOpenIframe("{:Url('/manage/cloud.log.smsLog/edit')}?id=" + data.id, '编辑');
                    break;
                case 'del':
                    del(obj.data.id);
                    break;

            }
        });

        form.on('submit(searchBtn)', function (data) {
            reload(1);

            return false;
        })
        element.on('tab(log)', function(elem){
            var log_name =  $(this).attr('data-log-name');
            var cols_log = {
                'sms_send_log':[
                    {type:'checkbox', fixed: 'left'},
                    {field: 'id', title: '序号', align: 'center', fixed: 'left'},
                    {field: 'member_id', title: '租户ID', align: 'center', templet: '#member_id'},
                    {field: 'event', title: '事件', align: 'center', templet: '#event'},
                    {field: 'mobile', title: '手机号', align: 'center', templet: '#mobile'},
                    {field: 'code', title: '验证码', align: 'center', templet: '#code'},
                    {field: 'times', title: '验证次数', align: 'center', templet: '#times'},
                    // {field: 'days', title: '有效天数', align: 'center', templet: '#days'},
                    {field: 'ip', title: 'IP', align: 'center', templet: '#ip'},
                    {field: 'create_time', title: '创建时间', align: 'center', templet: '#create_time'},

                    {title: '操作', toolbar: '#listBar', align: 'center', fixed: "right"}
                ],
            };
            var clos_log_now = cols_log[log_name]
            //执行列表
            table.render({
                elem: '#list',
                url: "{:Url('/manage/cloud.log.smsLog/index')}",
                where: getWhere(),
                response: {
                    statusCode: 200,  //规定成功的状态码，默认：0
                },
                parseData: function (res) { //res 即为原始返回的数据
                    return {
                        "code": res.code, //解析接口状态
                        "msg": res.msg, //解析提示文本
                        "count": res.data.data.total, //解析数据长度
                        "data": res.data.data.list //解析数据列表
                    };
                },
                toolbar: '#listToolbar',
                cols: [clos_log_now],
                limits: [10, 15, 20, 25, 50, 100],
                limit: 10,
                page: true
            });
        });


    });

    //删除
    function del(ids) {
        layer.confirm('确认删除?', function (index) {
            //ajax调用后台接口
            bwajax.post("{:Url('/manage/cloud.log.smsLog/del')}?ids=" + ids)
                .then(function (response) {
                    if (response.data.data.errcode === 0) {
                        layer.msg('删除成功', {icon: 1});
                        reload();
                    } else {
                        layer.msg(response.data.msg, {icon: 2});
                    }
                });
            layer.close(index);
        });
    }
</script>
{/block}